﻿

function Hide(id) {
            ids = id.split(',');
            for (i = 0; i < ids.length; i++) {
                $('#' + ids[i]).hide();
            }
}
//ids,starFields, messageFields comma separation should be same length
function RequiredFieldValidation(id, starField, messageField) {

    isValid = true;
    totalValid = 0;
    i = 0;
    if (id != '' && starField != '' && messageField != '') {
        ids = id.split(',');
        starFields = starField.split(',');
        messageFields = messageField.split(',');
        for (i = 0; i < ids.length; i++) {
            obj = document.getElementById([ids[i]]);
            if (!obj.disabled) {
                sF = $("#" + [starFields[i]]);
                mF = $("#" + [messageFields[i]]); 
                
                if (IsEmpty(obj.value)) {

                    sF.css("display", "inline");                  
                    sF.siblings("br").remove();                
                    mF.css("display", "inline");
                    mF.before("<br/>");
                    isValid = false;

                }
                else {

                    mF.css("display", "none");                    
                    sF.css("display", "none");
                    sF.siblings("br").remove();

                }

            }
        }
    }

    return isValid;

}
//ids,starFields, messageFields comma separation should be same length
function NumberFieldValidation(id, starField, messageField) {

    isValid = true;
    totalValid = 0;
    i = 0;
    if (id != '' && starField != '' && messageField != '') {
        ids = id.split(',');
        starFields = starField.split(',');
        messageFields = messageField.split(',');
        for (i = 0; i < ids.length; i++) {
            obj = document.getElementById([ids[i]]);
            if (!obj.disabled && !IsEmpty(obj.value)) {

                sF = $("#" + [starFields[i]]);
                mF = $("#" + [messageFields[i]]);              
                if (IsNotNumber(obj.value)) {

                    sF.css("display", "inline");
                    sF.siblings("br").remove();
                    mF.css("display", "inline");
                    mF.before("<br/>");
                    isValid = false;

                }
                else {

                    mF.css("display", "none");
                    sF.css("display", "none");
                    sF.siblings("br").remove();

                }

            }
        }
    }

    return isValid;

}
function IsEmpty(val) {
    var re = /\s/g; //Match any white space including space, tab, form-feed, etc.
    RegExp.multiline = true; // IE support
    var str = val.replace(re, "");
    if (str.length == 0) {
        return true;
    } else { return false; }
}

function IsNotNumber(val) {
    if (!IsEmpty(val)) {
        return isNaN(val)
    }
    return true;
}
function ApplyEnter(e, targetId) {
    var btnApply = null;
    e = e || window.event;
    if (e.keyCode == 13) {
        btnApply = $get(targetId);
        if (btnApply) {
            btnApply.focus();
            if (btnApply.onclick()) {
                eval(document.getElementById(targetId).getAttribute('href'))
            }
            else {
                return false;
            }

        }
        return false;
    }
    return true;
}
function TriggerSubmit(e, targetId) {
    var btnApply = null;
    e = e || window.event;
    if (e.keyCode == 13) {
        btnApply =$('#' + targetId);
        if (btnApply) {
            btnApply.focus();
            btnApply.trigger('click')
            //eval(btnApply.attr('href'))          

        }
        return false;
    }
    return true;
}

function ValidateEmail(id, starField, messageField) {
    isValid = true;
    totalValid = 0;
    i = 0;
    if (id != '' && starField != '' && messageField != '') {
        ids = id.split(',');
        starFields = starField.split(',');
        messageFields = messageField.split(',');
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        for (i = 0; i < ids.length; i++) {
            obj = document.getElementById([ids[i]]);
            if (!obj.disabled && !IsEmpty(obj.value)) {
                sF = $("#" + [starFields[i]]);
                mF = $("#" + [messageFields[i]]);  
                if (!reg.test(obj.value)) {

                     
                    sF.css("display", "inline");
                    sF.siblings("br").remove();
                    mF.css("display", "inline");
                    mF.before("<br/>");
                    isValid = false;

                }
                else {

                    mF.css("display", "none");
                    sF.css("display", "none");
                    sF.siblings("br").remove();

                }

            }
        }
    }

    return isValid;
}
function submitform(id) {
    $get(id).submit();
}
$(document).ready(function () {
    $(".optiontitle").live("focus", function () {
        $(".optiontitle option").each(function () {
            $(this).attr('title', $(this).html());
        });
    })
    $(".number").live("keyup", function () {
        this.value = this.value.replace(/[^0-9\.]/g, '');        
    });
})